Do not show a "Dry Run" button when editing a non-dry-runnable agent.

Akinori MUSHA 10 years ago
parent
commit
45ab179cc7
2 changed files with 11 additions and 12 deletions
  1. 8 11
      app/assets/javascripts/pages/agent-edit-page.js.coffee
  2. 3 1
      app/views/agents/_options.erb

+ 8 - 11
app/assets/javascripts/pages/agent-edit-page.js.coffee

@@ -7,8 +7,7 @@ class @AgentEditPage
7 7
     if $("#agent_type").length
8 8
       $("#agent_type").on "change", => @handleTypeChange(false)
9 9
       @handleTypeChange(true)
10
-
11
-    unless $('agent-dry-run-button').prop('disabled')
10
+    else
12 11
       @enableDryRunButton()
13 12
 
14 13
   handleTypeChange: (firstTime) ->
@@ -53,10 +52,7 @@ class @AgentEditPage
53 52
           $('.agent-options').html(json.form_options) if json.form_options?
54 53
           window.jsonEditor = setupJsonEditor()[0]
55 54
 
56
-        if json.can_dry_run
57
-          @enableDryRunButton()
58
-        else
59
-          @disableDryRunButton()
55
+        @enableDryRunButton()
60 56
 
61 57
         window.initializeFormCompletable()
62 58
 
@@ -138,9 +134,10 @@ class @AgentEditPage
138 134
 
139 135
   invokeDryRun: (e) ->
140 136
     e.preventDefault()
141
-    $(".agent-dry-run-button").prop('disabled', true)
137
+    button = this
138
+    $(button).prop('disabled', true)
142 139
     $('body').css(cursor: 'progress')
143
-    $.ajax type: 'POST', url: $(".agent-dry-run-button").data('action-url'), dataType: 'json', data: $(@form).serialize()
140
+    $.ajax type: 'POST', url: $(button).data('action-url'), dataType: 'json', data: $(button.form).serialize()
144 141
       .always =>
145 142
         $("body").css(cursor: 'auto')
146 143
       .done (json) =>
@@ -171,10 +168,10 @@ class @AgentEditPage
171 168
           find('.agent-dry-run-memory').text(json.memory)
172 169
         $('#dynamic-modal').modal('show').on 'hidden.bs.modal', ->
173 170
           $('#dynamic-modal').remove()
174
-          $(".agent-dry-run-button").prop('disabled', false)
175
-      .fail (xhr, status, error) =>
171
+          $(button).prop('disabled', false)
172
+      .fail (xhr, status, error) ->
176 173
         alert('Error: ' + error)
177
-        $(".agent-dry-run-button").prop('disabled', false)
174
+        $(button).prop('disabled', false)
178 175
 
179 176
 $ ->
180 177
   Utils.registerPage(AgentEditPage, forPathsMatching: /^agents/)

+ 3 - 1
app/views/agents/_options.erb

@@ -24,5 +24,7 @@
24 24
 <% end %>
25 25
 <div class="form-group">
26 26
   <%= submit_tag "Save", :class => "btn btn-primary" %>
27
-  <%= button_tag class: 'btn btn-default agent-dry-run-button', type: 'button', disabled: !agent.can_dry_run?, 'data-action-url' => agent.persisted? ? dry_run_agent_path(agent) : dry_run_agents_path do %><%= icon_tag('glyphicon-refresh') %> Dry Run<% end %>
27
+  <% if agent.can_dry_run? %>
28
+    <%= button_tag class: 'btn btn-default agent-dry-run-button', type: 'button', 'data-action-url' => agent.persisted? ? dry_run_agent_path(agent) : dry_run_agents_path do %><%= icon_tag('glyphicon-refresh') %> Dry Run<% end %>
29
+  <% end %>
28 30
 </div>